package logic

import (
	"context"
	"good_srv/model/mysql"

	"good_srv/good"
	"good_srv/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type GoodStatusLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGoodStatusLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GoodStatusLogic {
	return &GoodStatusLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *GoodStatusLogic) GoodStatus(in *good.GoodStatusRequest) (*good.GoodStatusResponse, error) {
	// todo: add your logic here and delete this line
	var goods []mysql.Good
	mysql.DB.Where("status=?", in.Status).Find(&goods)
	var allgood []*good.GoodStatus
	for _, m := range goods {
		lists := good.GoodStatus{
			Title:  m.Title,
			Cover:  m.Cover,
			Status: m.Status,
			Stock:  m.Stock,
			Price:  float32(m.Price),
			Likes:  m.Likes,
		}
		allgood = append(allgood, &lists)
	}
	return &good.GoodStatusResponse{
		List: allgood,
	}, nil
}
